package com.shopping.mapper;

import com.shopping.pojo.Product;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ProductMapper {
    @Select("select * from product")
    List<Product> list();

    @Select("select * from product where id = #{id}")
    Product getById(Integer id);

    @Select("select * from product where name = #{name}")
    Product getByName(String name);
    //添加商品
    @Insert("insert into product(name, description, type, image, price, stock) values(#{name},#{description},#{type},#{image},#{price},#{stock})")
    void addProduct(Product product);
    //管理员删除商品
    @Delete("delete from product where id = #{id}")
    void deleteProduct(Integer id);
    //管理员编辑产品
    void updateProduct(Product product);
    //把产品添加到该用户浏览记录
    @Insert("insert into browse(user_id, product_id, image, name) values(#{UserId},#{product.id},#{product.image},#{product.name})")
    void addBrowseLog(Product product,Integer UserId);
}
